package com.contest.interceptor;

import com.contest.constant.CommonsConstant;
import com.contest.entity.MerchantInfo;
import com.contest.entity.UserInfo;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 后台管理员登录拦截
 */
public class AdminRequestInterceptor implements HandlerInterceptor {
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {
        MerchantInfo userInfo = (MerchantInfo) request.getSession().getAttribute(CommonsConstant.LOGIN_SESSION);
        if(userInfo == null){
            request.setAttribute("msg","请登录!");
            request.getRequestDispatcher("/login.jsp").forward(request,response);
            return false;
        }else {
            return true;
        }

    }

    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}
